#include "shm.hpp"
#include "fifo.hpp"

int main()
{
    // 建立共享内存
    Shm MCshm(MyShmPath, Id, Creater);
    char *shmaddr = (char *)MCshm.Addr();
    // 建立管道来保护
    Fifo MCfifo(MyFifoPath, Creater);
    if (MCfifo.OpenForRead())
    {
        while (true)
        {
            std::string message;
            int n = MCfifo.ReadFifo(&message);
            if (n == 0)
            {
                std::cout << "写端结束，读端也结束" << std::endl;
                break;
            }
            else if (n > 0)
            {
                std::cout << message << std::endl;
                std::cout << "从共享内存读取到的内容:" << shmaddr << std::endl;
            }
            else
            {
                std::cout<<"读端代码有问题"<<std::endl;
                break;
            }
        }
    }
}